import 'package:flutter/material.dart';
import 'package:wallpaper_app/components/SideBar/tabbar_nav.dart';
import 'package:wallpaper_app/pages/images/suyan/random_mage_list.dart';

class RandomImagePc extends StatefulWidget {
  const RandomImagePc({super.key});

  @override
  State<RandomImagePc> createState() => _RandomImageState();
}

class _RandomImageState extends State<RandomImagePc>
    with TickerProviderStateMixin {
  List childTypes = [];
  late TabController tabController;
  int activeIndex = 0;
  PageController pageController = PageController(initialPage: 0);
  // 1：美女，2：动漫，3：风景，4：游戏，5：明星，6：机械，7：动物，8：文字，9：城市，10：视觉，11：物语，：12：情感，13：设计，14：男人
  List types = [
    [2, '动漫'],
    [1, '美女'],
    [3, '风景'],
    [4, '游戏'],
    [5, '明星'],
    [6, '机械'],
    [7, '动物'],
    [8, '文字'],
    [9, '城市'],
    [10, '视觉'],
    [11, '物语'],
    [12, '情感'],
    [13, '设计'],
    [14, '男人'],
  ];
  List<String> subList = [];

  @override
  void initState() {
    for (var i = 0; i < types.length; i++) {
      subList.add(types[i][1]);
    }
    super.initState();
    tabController = TabController(length: subList.length, vsync: this);
    tabController.addListener(() {
      setState(() {
        activeIndex = tabController.index;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        TabbarNav(
          subList: subList,
          tabController: tabController,
          pageController: pageController,
        ),
        Expanded(
            child: PageView(
          controller: pageController,
          children: [
            for (var i = 0; i < subList.length; i++)
              RandomMageList(
                format: types[i][0],
                screen: 1,
              ),
          ],
          onPageChanged: (index) {
            setState(() {
              activeIndex = index;
            });
            tabController.animateTo(index);
          },
        ))
      ],
    );
  }
}
